package org.ala.tiktools_clickhouse_generator.generator.fields;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.ala.tiktools_clickhouse_generator.config.ConfigInfo;
import org.ala.tiktools_clickhouse_generator.generator.AbstractCreator;
import org.ala.tiktools_clickhouse_generator.generator.entity.EntityInfo;
import org.ala.tiktools_clickhouse_generator.table.TableInfo;
import org.ala.tiktools_clickhouse_generator.tools.FileTools;

import freemarker.template.TemplateException;

/**
 *
 *	@author ala
 *	@date 2025年6月9日
 */
public class FieldsCreator extends AbstractCreator {

	
	/**
	 * 	生成
	 * @throws TemplateException 
	 * @throws IOException 
	 */
	public FieldsInfo create(ConfigInfo c, TableInfo ti, EntityInfo ei) throws IOException, TemplateException {
		Map<String, Object> dataMeta = new HashMap<>();
		FieldsInfo fi = new FieldsInfo(ti, c.getPart().getAuthor(), ei);
        dataMeta.put("f", fi);
        
        String out = c.getPart().getOut().getEntity().getPkg();
        out = this.getOutRootPath() + out.replaceAll("\\.", "/");
        FileTools.existsAndMakeDirs(out);
        out = out + "/" + fi.getClassName() + ".java";

        output("Fields.ftl", dataMeta, out);

        System.out.println("生成Fields类. path:" + out);
        return fi;
	}
}
